package com.hongxun.modules.csg.controller;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hongxun.common.utils.*;
import com.hongxun.config.PriceConfig;
import com.hongxun.modules.bss.entity.*;
import com.hongxun.modules.bss.service.DPictureService;
import com.hongxun.modules.csg.entity.*;
import com.hongxun.modules.csg.service.CArrivalRecordService;
import com.hongxun.modules.csg.service.CGoodsDetailService;
import com.hongxun.modules.csg.service.CPBaseService;
import com.hongxun.modules.sys.entity.SysDeptEntity;
import com.hongxun.modules.sys.entity.SysUserEntity;
import com.hongxun.modules.sys.service.ShiroService;
import com.lowagie.text.*;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.csg.service.CStackPointService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 物质堆放点
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-09-11 09:30:52
 */
@RestController
@RequestMapping("/csg/cstackpoint")
public class CStackPointController {
	@Autowired
	private CStackPointService cStackPointService;
	@Autowired
	private CArrivalRecordService cArrivalRecordService;
	@Autowired
	protected ShiroService shiroService;
	@Autowired
	private CGoodsDetailService cGoodsDetailService;
	@Autowired
	private CPBaseService cPBaseService;
	@Autowired
	private DPictureService dPictureService;
	@Value("${com.hongxun.IMAGEROTT}")
	private String ROOT;

	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("csg:cstackpoint:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
		if (params.get("pGuid")!=null && !params.get("pGuid").toString().equals("")) {
			wheres += " and p_guid='"+params.get("pGuid").toString()+"'";
		}else{
			wheres += " and 1=2 ";
		}
		if(query.get("state")!=null && !query.get("state").toString().equals("isdelno")){
			wheres +=" and s_p_datastate != '删除' ";
		}
		if(query.get("stack")!=null && !query.get("stack").toString().equals("")){
			wheres +=" and guid != '"+query.get("stack").toString()+"' ";
		}
		query.put("filterSql",wheres+" ");
		List<CStackPointEntity> cStackPointList = cStackPointService.queryList(query);
		int total = cStackPointService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(cStackPointList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}


	/**
	 *  查询堆放点
	 *
	 * @param params
	 * @return
	 */
	@RequestMapping("/select/{guid}")
	public R info(@RequestParam Map<String , Object> params , @PathVariable("guid") String guid){

		//查询列表数据
		Map<String, Object> map = new HashMap<>();
		String wheres = " p_guid = '" + guid+"'";
		map.put("filterSql", wheres + " ");
		List<CStackPointEntity> cStackPointEntities = cStackPointService.queryList(map);

		return R.ok().put("returnlist", cStackPointEntities);
	}


	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	@RequiresPermissions("csg:cstackpoint:info")
	public R info(@PathVariable("guid") String guid){
		CStackPointEntity cStackPoint = cStackPointService.queryObject(guid);

		return R.ok().put("cStackPoint", cStackPoint);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("csg:cstackpoint:save")
	public R save(@RequestBody CStackPointEntity cStackPoint){
		cStackPoint.setSPDatastate("新增");
		cStackPointService.save(cStackPoint);
		
		return R.ok();
	}


	/**
	 * 新增堆放点
	 *
	 * @param cStackPoint
	 * @param pGuid
	 * @return
	 */
	@RequestMapping("/saveNew/{pGuid}")
	@RequiresPermissions("csg:cstackpoint:save")
	public R save(@RequestBody CStackPointEntity cStackPoint , @PathVariable String pGuid ,
				  HttpServletRequest request)
	{

		// TODO: 2018/9/19  保存堆放点的同时，保存到货记录

		Map<String , Object > cStackPointMap = new HashMap<>();
		CArrivalRecordEntity cArrivalRecordEntity = new CArrivalRecordEntity();

		//保存堆放点
		cStackPoint.setPGuid(pGuid);
		cStackPoint.setSPDatastate("新增");
		cStackPointService.save(cStackPoint);

		//查询堆放点ID
		String whereCStackPoint = " 1=1 and s_p_name='"+cStackPoint.getSPName()+"' ";
		cStackPointMap.put("filterSql",whereCStackPoint);
		List<CStackPointEntity> cStackPointEntityList = cStackPointService.queryList(cStackPointMap);
		String sPGuid = "";
		if (cStackPointEntityList != null) {
			for (CStackPointEntity cStackPointEntity : cStackPointEntityList) {
				sPGuid = cStackPointEntity.getGuid();
			}
		}

		//保存到货记录
/*
		//从header中获取token
		String token = request.getHeader("token");
		//如果header中不存在token，则从参数中获取token
		if(StringUtils.isBlank(token)){
			token = request.getParameter("token");
		}
		SysUserEntity sysUserEntity = shiroService.queryByToken(token);

		//设值
		cArrivalRecordEntity.setSPGuid(sPGuid);
		cArrivalRecordEntity.setSPName(cStackPoint.getSPName());
		cArrivalRecordEntity.setARUser(sysUserEntity.getUserId());
		cArrivalRecordEntity.setARUsername(sysUserEntity.getUsername());
		cArrivalRecordEntity.setARTime(new Date());
		cArrivalRecordEntity.setARDatastate("新增");
		cArrivalRecordEntity.setPGuid(pGuid);
		cArrivalRecordService.save(cArrivalRecordEntity);*/

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("csg:cstackpoint:update")
	public R update(@RequestBody CStackPointEntity cStackPoint){
		cStackPoint.setSPDatastate("修改");
		cStackPointService.update(cStackPoint);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("csg:cstackpoint:delete")
	public R delete(@RequestBody String[] guids){
		cStackPointService.deleteBatch(guids);
		
		return R.ok();
	}

	/**
	 * 导出堆放点材料
	 *
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws DocumentException
	 */
	@RequestMapping("/exports")
	public void exports(HttpServletRequest request , HttpServletResponse response) throws IOException, DocumentException {

		//堆放点ID
		String guid = request.getParameter("guid");
		CStackPointEntity cStackPoint = cStackPointService.queryObject(guid);
		//项目名称
		String pGuid = cStackPoint.getPGuid();
		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);
		//设置下载文件的格式(表格)msword
//		response.setContentType("application/vnd.ms-excel;charset=utf-8");//表格
		response.setContentType("application/msword;charset=utf-8");//文档
		try {
//			response.setHeader("Content-Disposition", "attachment;filename=" + new String(((cStackPoint.getSPName()==null?"堆放点材料":cStackPoint.getSPName()) + ".xlsx").getBytes(), "iso-8859-1"));
			response.setHeader("Content-Disposition", "attachment;filename=" + new String(((cStackPoint.getSPName()==null?"堆放点材料":cpBaseEntity.getPBName()+"_"+cStackPoint.getSPName()) + ".doc").getBytes(), "iso-8859-1"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		//A4纸横向打印
		Document document = new Document(PageSize.A4.rotate());
		//字体设置
		BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

		RtfWriter2.getInstance(document, response.getOutputStream());
		Font titleFontye = new Font(bfChinese,8,Font.BOLD);
		HeaderFooter footer = new HeaderFooter(new Phrase("页码：",titleFontye), true);
		footer.setAlignment(1);
		footer.setBorder(Rectangle.NO_BORDER);
		document.setFooter(footer);
		document.open();
		//文件内容及格式
		setexports(document,bfChinese,cStackPoint);

		document.close();

	}

	/**
	 * 导出内容和文档样式
	 *
	 * @param document
	 * @param bfChinese
	 * @param cStackPoint
	 * @throws DocumentException
	 */
	public void setexports(Document document  ,BaseFont bfChinese ,	CStackPointEntity cStackPoint  ) throws DocumentException {

		Map<String ,Object> cStackMap = new HashMap<>();

		//堆放点名称
		String sPName = cStackPoint.getSPName();

		//1.查询所属堆放点下所有的到货记录
		String cStackWhere = " 1=1 and s_p_guid='"+cStackPoint.getGuid()+"' and a_r_datastate != '删除' and p_guid='"+cStackPoint.getPGuid()+"'";
		cStackMap.put("filterSql",cStackWhere);
		List<CArrivalRecordEntity> cArrivalList = cArrivalRecordService.queryList(cStackMap);

		cStackMap.remove("filterSql");
		cStackWhere = cStackWhere.substring(0,4);


		//2.查询所属到货记录下的物资清单
		if(cArrivalList.size() != 0){
			for (int i = 0; i < cArrivalList.size(); i++) {
				String guid = cArrivalList.get(i).getGuid();
				if (i == 0) {
					cStackWhere += " and a_r_guid = '"+guid+"' ";
				}else {
					cStackWhere += " or a_r_guid = '"+guid+"' ";
				}
			}
		}

		cStackMap.put("filterSql",cStackWhere+" ");
		List<CGoodsDetailEntity> cGoodsDetailList = cGoodsDetailService.queryList(cStackMap);

		//3.获取项目名称
		String pGuid = cStackPoint.getPGuid();
		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);


		//表题字体
		Font titleFont = new Font(bfChinese,11,Font.BOLD);
		//表格字体
		Font contextFont = new Font(bfChinese, 8, Font.NORMAL);
		//签字字体
		Font qinFont = new Font(bfChinese, 10, Font.NORMAL);
//		Paragraph title = new Paragraph("配网技改/修理项目申请书（适用于总投资100万元以下的配网技改/修理项目）");
//		title.setAlignment(Element.ALIGN_CENTER);
//		title.setFont(titleFont);
//		document.add(title);

//		Table table = new Table(13);
//		int[] withs = {1, 3, 3, 2, 2, 3,3, 2,2, 2, 2, 2,4};
		Table table = new Table(14);
		int[] withs = {1,1,1,1,1,1,1,1,1,1,1,1,1,1};
		table.setWidths(withs);
		/** 表格所占页面宽度 author:yyli Sep 15, 2010 */
		table.setWidth(90);
		/** 居中显示 author:yyli Sep 15, 2010 */
		table.setAlignment(Element.ALIGN_CENTER);
		/** 自动填满 author:yyli Sep 15, 2010 */
		table.setAutoFillEmptyCells(true);

		OutPutUtils.addcell(table, cpBaseEntity.getPBName()+"项目-"+sPName+"堆放点材料清单", 0, 14, true, contextFont);

		//材料清单列表
		OutPutUtils.addcell(table, "类别(材料/设备)", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "所属设备/材料ID", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "到货数", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "供货商", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "物质编码", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "材料大类", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "材料中类", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "材料标签", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "材料名称", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "主要技术参数", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "购置单位", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "购置总价", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "购置单价", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "单重（kg）", 0, 0, true, contextFont);


		for(CGoodsDetailEntity cGoodsDetailEntity :cGoodsDetailList)
		{
			OutPutUtils.addcell(table, cGoodsDetailEntity.getGDType(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cGoodsDetailEntity.getMDGuid(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cGoodsDetailEntity.getGDNum().toPlainString(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cGoodsDetailEntity.getGDBusine(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cGoodsDetailEntity.getGDCode(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cGoodsDetailEntity.getGDBigtype(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cGoodsDetailEntity.getGDMidtype(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cGoodsDetailEntity.getGDLabel(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cGoodsDetailEntity.getGDName(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cGoodsDetailEntity.getGDParameter(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table,cGoodsDetailEntity.getGDUnit(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table,cGoodsDetailEntity.getGDAllprice().toPlainString(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table,cGoodsDetailEntity.getGDPrice().toPlainString(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table,cGoodsDetailEntity.getGDWeight().toPlainString(), 0, 0, true, contextFont);
		}


		document.add(table);
	}







	/**
	 * 导出材料到场照片
	 *
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws DocumentException
	 */
	@RequestMapping("/exportsimg")
	public void exportsimg(HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException {


		//堆放点
		String guid = request.getParameter("guid");
		CStackPointEntity cStackPointEntity = cStackPointService.queryObject(guid);
		//项目名称
		String pGuid = cStackPointEntity.getPGuid();
		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);

		response.setContentType("application/msword;charset=utf-8");
		try {
			response.setHeader("Content-Disposition", "attachment;filename=" + new String(((cStackPointEntity.getSPName()==null?"":cpBaseEntity.getPBName()+"_"+cStackPointEntity.getSPName()) + "_材料照片.doc").getBytes(), "iso-8859-1"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		Document document = new Document();
		BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

		RtfWriter2.getInstance(document, response.getOutputStream());
		Font titleFontye = new Font(bfChinese,8,Font.BOLD);
		HeaderFooter footer = new HeaderFooter(new Phrase("页码：",titleFontye), true);
		footer.setAlignment(1);
		footer.setBorder(Rectangle.NO_BORDER);
		document.setFooter(footer);
		document.open();
		setexportsimg(document,bfChinese,cStackPointEntity);

		document.close();
	}

	/**
	 * 设置表格格式
	 *
	 * @param document
	 * @param bfChinese
	 * @param
	 * @throws DocumentException
	 * @throws IOException
	 */
	public void setexportsimg(Document document  ,BaseFont bfChinese ,	CStackPointEntity cStackPointEntity  ) throws DocumentException, IOException {

		Map<String ,Object> cStackMap = new HashMap<>();
		//项目名称
		String pGuid = cStackPointEntity.getPGuid();
		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);

		//表题字体
		Font titleFont = new Font(bfChinese,11,Font.BOLD);
		//表格字体
		Font contextFont = new Font(bfChinese, 8, Font.NORMAL);
		// 签字字体
		Font qinFont = new Font(bfChinese, 10, Font.NORMAL);
		Paragraph title = new Paragraph((cStackPointEntity.getSPName()==null?"":cpBaseEntity.getPBName()+"_"+cStackPointEntity.getSPName()) + "_材料照片");
		title.setAlignment(Element.ALIGN_CENTER);
		title.setFont(titleFont);
		document.add(title);

		//1.查询所属堆放点下所有的到货记录
		/*String cStackWhere = " 1=1 and s_p_guid='"+cStackPointEntity.getGuid()+"' and a_r_datastate != '删除' and p_guid='"+cStackPointEntity.getPGuid()+"'";
		cStackMap.put("filterSql",cStackWhere);
		List<CArrivalRecordEntity> cArrivalList = cArrivalRecordService.queryList(cStackMap);

		cStackMap.remove("filterSql");
		cStackWhere = cStackWhere.substring(0,4);


		//2.查询所属到货记录下的物资清单
		for (int i = 0; i < cArrivalList.size(); i++) {
			String aRguid = cArrivalList.get(i).getGuid();
			if (i == 0) {
				cStackWhere += " and a_r_guid = '"+aRguid+"' ";
			}else {
				cStackWhere += " or a_r_guid = '"+aRguid+"' ";
			}
		}

		cStackMap.put("filterSql",cStackWhere+" ");
		List<CGoodsDetailEntity> cGoodsDetailList = cGoodsDetailService.queryList(cStackMap);

		addCStackPointImg(document, cStackPointEntity, contextFont, cGoodsDetailList);*/




		String cStackWhere = " 1=1 and guid='"+cStackPointEntity.getGuid()+"' and s_p_datastate != '删除' and p_guid='"+cStackPointEntity.getPGuid()+"'";
		cStackMap.put("filterSql",cStackWhere);
		List<CStackPointEntity> cStackPointEntityList = cStackPointService.queryList(cStackMap);

		addCStackPointImg(document, cStackPointEntity, contextFont, cStackPointEntityList);

	}

	/**
	 *
	 *
	 * @param document
	 * @param cStackPointEntity
	 * @param contextFont
	 * @param
	 * @throws DocumentException
	 * @throws IOException
	 */
	private void addCStackPointImg(Document document, CStackPointEntity cStackPointEntity , Font contextFont, List<CStackPointEntity> cStackPointEntityList) throws DocumentException, IOException {

		for (CStackPointEntity cGoodsDetailEntity : cStackPointEntityList) {

			Map<String , Object> cGoodsDetailMap = new HashMap<>();
			String cScheduleWhere = " 1=1 and p_guid= '"+cGoodsDetailEntity.getPGuid()+
					"' and p_status = '施工' and p_label like'%材料%'" +
					" and p_p_guid='"+cStackPointEntity.getGuid()+"' and p_datastate !='删除' ";
			cGoodsDetailMap.put("filterSql", cScheduleWhere + " ");
			List<DPictureEntity> dPictureList = dPictureService.queryList(cGoodsDetailMap);
			if(dPictureList.size()>0) {

				Table table = new Table(6);
				int[] withs = {1, 2, 1, 2, 1, 2};
				table.setWidths(withs);
				/** 表格所占页面宽度 author:yyli Sep 15, 2010 */
				table.setWidth(90);
				/** 居中显示 author:yyli Sep 15, 2010 */
				table.setAlignment(Element.ALIGN_CENTER);
				/** 自动填满 author:yyli Sep 15, 2010 */
				table.setAutoFillEmptyCells(true);

				OutPutUtils.addcell(table, cStackPointEntity.getSPName() + "(材料)", 0, 6, true, contextFont);
				int chishu = dPictureList.size() / 3;
				int yushu = dPictureList.size() % 3;

				if (yushu > 0) {
					chishu = chishu + 1;
				}
				//一行显示3张照片
				for (int i = 0; i < chishu;i++) {
					boolean one = false;
					boolean two = false;
					boolean three = false;

					if ((3 * i) < dPictureList.size() ) {
						one = true;
					}
					if (((3 * i) + 1) < dPictureList.size()) {
						two = true;
					}
					if (((3 * i) + 2) < dPictureList.size()) {
						three = true;
					}
					if (one) {
						File file=new File(ROOT +   dPictureList.get(3 * i).getPServeraddress());
						if(file.exists()) {
							OutPutUtils.addcellimg(table, ROOT +   dPictureList.get(3 * i).getPServeraddress(), 8, 2, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
					}
					if (two) {
						File file=new File(ROOT +   dPictureList.get((3 * i)+1).getPServeraddress());
						if(file.exists()) {
							OutPutUtils.addcellimg(table, ROOT +   dPictureList.get((3 * i)+1).getPServeraddress(), 8, 2, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
					}
					if (three) {
						File file=new File(ROOT +   dPictureList.get((3 * i)+2).getPServeraddress());
						if(file.exists()) {
							OutPutUtils.addcellimg(table, ROOT +   dPictureList.get((3 * i)+2).getPServeraddress(), 8, 2, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
					}

					//照片名称
					OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
					if (one) {
						OutPutUtils.addcell(table, dPictureList.get(3 * i).getPLabel(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
					if (two) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPLabel(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
					if (three) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPLabel(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}

					//照片来源：相册or相机
					OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
					if (one) {
						OutPutUtils.addcell(table, dPictureList.get(3 * i).getPPResour(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
					if (two) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPPResour(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
					if (three) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPPResour(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}

					//时间
					OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
					if (one) {
						OutPutUtils.addcell(table, dPictureList.get(3 * i).getPTime() == null ? "" : DateUtils.format(dPictureList.get(3 * i).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
					if (two) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPTime() == null ? "" : DateUtils.format(dPictureList.get((3 * i) + 1).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
					if (three) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPTime() == null ? "" : DateUtils.format(dPictureList.get((3 * i) + 2).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
				}
				document.add(table);
			}

		}
	}

}
